/**
 * 
 */
package club325.webchat.database.hibernate.implement;

import java.util.List;

import org.hibernate.Query;

import club325.webchat.database.hibernate.dao.HibernateUtil;
import club325.webchat.database.hibernate.dao.NoticeDAO;
import club325.webchat.database.hibernate.domain.Notice;

/**
 * @author Sider
 *
 */
public class NoticeImplement implements NoticeDAO
{

	/* (non-Javadoc)
	 * @see club325.webchat.database.hibernate.dao.NoticeDAO#saveNotice(club325.webchat.database.hibernate.domain.Notice)
	 */
	public void saveNotice(Notice notice)
	{
		HibernateUtil.add(notice);
	}

	/* (non-Javadoc)
	 * @see club325.webchat.database.hibernate.dao.NoticeDAO#deleteNotice(club325.webchat.database.hibernate.domain.Notice)
	 */
	public void deleteNotice(Notice notice)
	{
		HibernateUtil.delete(notice);
	}

	/* (non-Javadoc)
	 * @see club325.webchat.database.hibernate.dao.NoticeDAO#findNoticebyid(int)
	 */
	public Notice findNoticebyid(int id)
	{
		return (Notice)HibernateUtil.get(Notice.class, id);
	}

	/* (non-Javadoc)
	 * @see club325.webchat.database.hibernate.dao.NoticeDAO#findNoticebyMemberID(java.lang.String)
	 */
	@SuppressWarnings("unchecked")
	public List<Notice> findNoticebyOwnerID(String memberID)
	{
		String HQL = "FROM Notice AS notice WHERE notice.ownerID = ?";
		Query q = HibernateUtil.getSession().createQuery(HQL);
		q.setString(0,memberID);
		return q.list();
	}

	@SuppressWarnings("unchecked")
	public List<Notice> findAllNotice()
	{
		String HQL = "FROM Notice AS notice";
		Query q = HibernateUtil.getSession().createQuery(HQL);
		
		return q.list();
	}

	@SuppressWarnings("unchecked")
	public List<Notice> findBoticebyTargetID(String TargetID)
	{
		String HQL = "FROM Notice AS notice WHERE notice.TargetID = ?";
		Query q = HibernateUtil.getSession().createQuery(HQL);
		q.setString(0, TargetID);
		return q.list();
	}
}
